﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Import Namespace="WebHoiChoMuaBan.Models" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Helpers" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	News
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="HeadHolder" runat="server">
    <script type="text/javascript" src="/../Scripts/public.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
//            $("#Pages").change(function () {
//                $.get("/AdminNews/Index",
//                   { index: $(this).val() },
//                   function (data) {
//                       var selectedPage = $("#Pages").val();
//                       var newsTypeId = $("#newsTypeId").val();
//                       window.location = "/AdminNews/Index?selectedPage=" + selectedPage + "&newsTypeId=" + newsTypeId;
//                   });
//            });

            // Check and Uncheck all combobox
            $("#checkbox_all").click(function () {
                var n = $("#checkbox_all:checked").length;
                if (n == 1) {
                    $(".input_checkbox:not(#checkbox_news,#checkbox_member,#checkbox_product)").attr('checked', true);
                }
                else
                    $(".input_checkbox:not(#checkbox_news,#checkbox_member,#checkbox_product)").attr('checked', false);
            });

        });
    </script>
    
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <form action="<%= Url.Action("Controller","AdminNews") %>" method="post" enctype="multipart/form-data" id="frm_News">
        <input type="hidden" id="hidCmd" name="hidCmd" />
        <div class="col_left hoicho_marin_leftright content_right">
            <div class="content_group">
                <div class="col_left content_group hoicho_margin_topbottom">
                    <div class="private_button_upload col_left hoicho_margin_leftright">
                        <a href="javascript:void(0)" onclick="SubmitData_Ajax('frm_News', 'del'); return false;" name="Delete">
                            <img src="<%=ResolveUrl("~/Content/Images/icon_plus_up.gif") %>" alt=""/>Xóa
                        </a>
                    </div>
                    <div class="private_button_upload col_left hoicho_margin_leftright">
                        <a href="javascript:void(0)"><img src="<%=ResolveUrl("~/Content/Images/icon_plus_up.gif") %>" alt=""/>
                        Cắt</a>
                    </div>
                    <div class="private_button_upload col_left hoicho_margin_leftright">
                        <a href="javascript:void(0)"><img src="<%=ResolveUrl("~/Content/Images/icon_plus_up.gif") %>" alt=""/>
                        Dán</a>
                    </div>
                    <div class="private_button_upload col_left">
                        <a href="javascript:void(0)" onclick="SubmitData_Ajax('frm_News','ChangeState'); return false;" name="ChangeState"><img src="<%=ResolveUrl("~/Content/Images/icon_plus_up.gif") %>" alt=""/>
                        Chuyển trạng thái</a>
                    </div>
                    <%--<div style="float:right">
                        
                    </div>--%>
                </div>
                <div class="col_right" style="width: 100px"><a href="<%= Url.Action("AddNews","AdminNews") %>" class="hoicho_bt_submit_reg">Đăng tin</a></div>
                <div class="clear"></div>
                <div class="col_left hoicho_margin_leftright font_bold">
                            <%
                                NewsHelper.FetchNewsResult listNews = (NewsHelper.FetchNewsResult)ViewData["NewsList"];
                                int p, i;
                                int newsTypeId = ViewData["NewsTypeId"] == null ? 0 : (int)ViewData["NewsTypeId"];
                                if (Request.QueryString["p"] == null && !int.TryParse(Request.QueryString["p"], out p))
                                //if(p!=0)
                                {
                                    p = 1;
                                }
                                else p = int.Parse(Request.QueryString["p"]);
                                 %>
                            <% if (p > 1) { %><a href='<%=string.Format("{0}?p={1}&newsTypeId={2}'",
                                                                    Url.Action("Index", "AdminNews"),
                                                                    p-1,newsTypeId) %>'><img src="/../Content/Images/arrow_breakpage_left.gif" alt="">&nbsp;Trang trước</a> <% } %>
                            <%
                                if (p > 3)
                                    Response.Write(string.Format("<a href='{0}?p={1}&newsTypeId={2}'{3}>{4}</a> ",
                                                                    Url.Action("Index", "AdminNews"),
                                                                    1,newsTypeId,
                                                                    string.Empty,
                                                                     1));
                                if (p > 4)
                                    Response.Write("...");
                                int total = listNews.totalPages;
                                int from = (p - 2 < 1 ? 1 : p - 2);
                                int to = (p + 2 >= total ? total : p + 2);
                                for (i = from; i <= to; i++)
                                    Response.Write(string.Format("<a href='{0}?p={1}&newsTypeId={2}'{3}>{4}</a> ",
                                                                    Url.Action("Index", "AdminNews"),
                                                                    i,newsTypeId, 
                                                                    (i==p ? "class='menu_select'" : string.Empty),
                                                                     i));
                                if (p <= total - 4)
                                    Response.Write("...");
                                if (p <= total - 3)
                                    Response.Write(string.Format("<a href='{0}?p={1}&newsTypeId={2}'{3}>{4}</a> ",
                                                                    Url.Action("Index", "AdminNews"),
                                                                    total,newsTypeId,
                                                                    string.Empty,
                                                                    total));
                             %>
            
                            <% if (p < listNews.totalPages)
                               { %><a href='<%=string.Format("{0}?p={1}&newsTypeId={2}'",
                                                                    Url.Action("Index", "AdminNews"),
                                                                    p+1,newsTypeId) %>'>Trang sau&nbsp;<img src="/../Content/Images/arrow_breakpage_right.gif" alt=""></a> <% } %>
                            <%--<% }  %>--%>
                        </div>
            </div>
            <div class="private_group_friend">
                <table width="765" border="0">
                    <tr bgcolor="#f5f7fb" class="border_bottom">
                        <td width="3%"><input id="checkbox_all" class="input_checkbox" type="checkbox" name="checkbox_all"/></td>
                        <td width="57%"><p class="font_bold" for="checkbox5">Nội dung</p></td>
                        <td width="10%"><span class="font_bold">Trạng thái</span></td>
                        <td width="9%" align="center"><p class="font_bold">Ngày gửi</p></td>
                        <td width="7%" align="center"><span class="font_bold">Admin</span></td>
                        <td width="14%">&nbsp;</td>
                    </tr>
                    <%
                        if (ViewData["NewsList"] != null)
                        {
                            int j = 0;
                            if (listNews.news.Count > 0)
                            {
                                Response.Write("<input type='hidden' id='p' name='p' value='"+p+"'>");
                                foreach (var news in listNews.news)
                                {
                                    if (j++ % 2 == 0)
                                        Response.Write("<tr>");
                                    else
                                        Response.Write("<tr bgcolor='#e6e6e6'>");
                                    Response.Write("<td><input id='checkbox" + news.NewsId + "' class='input_checkbox' type='checkbox' name='checkbox' value='" + news.NewsId + "'/></td>");
                                    Response.Write("<td><span class='font_bold'>" + news.NewsTitle + "</span></td>");
                                    Response.Write("<td align='center'><span>" + (news.NewsState == true ? "Xuất bản" : "Chờ") + "</span></td>");
                                    Response.Write("<td align='center'><span class='font_bold'>" + news.NewsDate.ToString("dd/MM/yyyy") + "</span></td>");
                                    Response.Write("<td align='center'>" + news.Member.MemUsername + "</td>");
                                    Response.Write("<td align='right'><div class='private_button_upload col_right'>");
                                    Response.Write("<a href='/AdminNews/DeleteNews?newsId=" + news.NewsId + "'><img src='/../Content/Images/icon_plus_up.gif'/>Xóa</a></div>");
                                    Response.Write("<div class='private_button_upload col_right hoicho_margin_leftright'>");
                                    Response.Write("<a href='/AdminNews/LoadNewsToEdit?newsId=" + news.NewsId + "'><img src='/../Content/Images/icon_plus_up.gif'/>Sửa</a></div></td>");
                                }
                            }
                            else
                            {
                                Response.Write("<tr><td colspan='5'>Không có dữ liệu </td></tr>"); 
                            }
                        }
                    %>
                </table>
                <br />
                <div class="col_left hoicho_margin_leftright font_bold">
                            <%
                                if (Request.QueryString["p"] == null && !int.TryParse(Request.QueryString["p"], out p))
                                //if(p!=0)
                                {
                                    p = 1;
                                }
                                else p = int.Parse(Request.QueryString["p"]);
                                 %>
                            <% if (p > 1) { %><a href='<%=string.Format("{0}?p={1}&newsTypeId={2}'",
                                                                    Url.Action("Index", "AdminNews"),
                                                                    p-1,newsTypeId) %>'><img src="/../Content/Images/arrow_breakpage_left.gif" alt="">&nbsp;Trang trước</a> <% } %>
                            <%
                                if (p > 3)
                                    Response.Write(string.Format("<a href='{0}?p={1}&newsTypeId={2}'{3}>{4}</a> ",
                                                                    Url.Action("Index", "AdminNews"),
                                                                    1,newsTypeId,
                                                                    string.Empty,
                                                                     1));
                                if (p > 4)
                                    Response.Write("...");
                                total = listNews.totalPages;
                                from = (p - 2 < 1 ? 1 : p - 2);
                                to = (p + 2 >= total ? total : p + 2);
                                for (i = from; i <= to; i++)
                                    Response.Write(string.Format("<a href='{0}?p={1}&newsTypeId={2}'{3}>{4}</a> ",
                                                                    Url.Action("Index", "AdminNews"),
                                                                    i,newsTypeId, 
                                                                    (i==p ? "class='menu_select'" : string.Empty),
                                                                     i));
                                if (p <= total - 4)
                                    Response.Write("...");
                                if (p <= total - 3)
                                    Response.Write(string.Format("<a href='{0}?p={1}&newsTypeId={2}'{3}>{4}</a> ",
                                                                    Url.Action("Index", "AdminNews"),
                                                                    total,newsTypeId,
                                                                    string.Empty,
                                                                    total));
                             %>
            
                            <% if (p < listNews.totalPages)
                               { %><a href='<%=string.Format("{0}?p={1}&newsTypeId={2}'",
                                                                    Url.Action("Index", "AdminNews"),
                                                                    p+1,newsTypeId) %>'>Trang sau&nbsp;<img src="/../Content/Images/arrow_breakpage_right.gif" alt=""></a> <% } %>
                            <%--<% }  %>--%>
                        </div>
            </div>
            <div class="content_group">
                <div class="col_left content_group hoicho_margin_topbottom">
                    <div class="private_button_upload col_left hoicho_margin_leftright">
                        <a href="javascript:void(0)" onclick="SubmitData_Ajax('frm_News', 'del'); return false;" name="Delete">
                            <img src="<%=ResolveUrl("~/Content/Images/icon_plus_up.gif") %>" alt=""/>Xóa
                        </a>
                    </div>
                    <div class="private_button_upload col_left hoicho_margin_leftright">
                        <a href="javascript:void(0)"><img src="<%=ResolveUrl("~/Content/Images/icon_plus_up.gif") %>" alt=""/>
                        Cắt</a>
                    </div>
                    <div class="private_button_upload col_left hoicho_margin_leftright">
                        <a href="javascript:void(0)"><img src="<%=ResolveUrl("~/Content/Images/icon_plus_up.gif") %>" alt=""/>
                        Dán</a>
                    </div>
                    <div class="private_button_upload col_left">
                        <a href="javascript:void(0)" onclick="SubmitData_Ajax('frm_News','ChangeState'); return false;" name="ChangeState"><img src="<%=ResolveUrl("~/Content/Images/icon_plus_up.gif") %>" alt=""/>
                        Chuyển trạng thái</a>
                    </div>
                </div>
            </div>
        </div>
    </form>
</asp:Content>
